<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
    <h:head>
        <title>Unhoused Inventories</title>
    </h:head>
    <f:view beforePhase="#{UserDisplayManagedBean.doDisplay}">
        <f:view beforePhase="#{WarehouseManagedBean.initViewforUnhousedInventories}">
            <h:body>
                <h:form prependId="false">
                    <p:growl id="growl" showDetail="true" /> 
                    <p:growl id="notif" showDetail="true"/>  
                    <p:poll interval="5"   
                            actionListener="#{MessageManagedBean.checkNewMessage}" immediate="true" update="notif" />
                    <div id="top" class="top">
                        <h:graphicImage value="/image/newHeader.jpg"/>
                    </div>
                    <div id="content" style="font-size:12px;font-family:Tahoma">

                        <table >
                            <tr><td>
                                    <p:toolbar style="background-color:darkred;font-size:100%;height:25px;width:100%"> 
                                        <p:toolbarGroup align="right">
                                            <p:button title="Home" image="ui-icon-home" outcome ="InventoryDeptWorkspace"/>                                  
                                            <p:button title="Notes" image="ui-icon-note" outcome="tasks"/>                                    
                                            <p:button title="Mail" outcome="messages"  image="ui-icon-mail-closed" />                                   
                                            <p:button title="Edit Preferences" image="ui-icon-gear"/>                                   
                                            <p:button title="Help" image="ui-icon-help"/>
                                            <p:commandButton title="Log Out" immediate="true" type="submit" image="ui-icon-close" actionListener="#{UserManagedBean.doLogout}"/> 
                                        </p:toolbarGroup>
                                    </p:toolbar></td>
                                <td>
                                    <h:graphicImage value="warehouse.gif" style="width:35px;height:35px" />
                                    <h:outputText value="         "/>
                                    <h:outputText value="Unhoused Inventories" style="font-family:Tahoma;font-size:20px;font-weight:bolder"/>
                                    <p:spacer width="100" height="10"/>
                                </td>
                            </tr>
                            <tr>

                                <td style="vertical-align:top">
                                    <p:menu style="width:200px;font-size: 12px;font-family: Tahoma;border-style: ridge">  
                                        <p:submenu label="Inventories" > 
                                            <p:menuitem value="New Product" url="http://localhost:8080/MerlionERP-war/SCM/addProduct.xhtml" ajax="false" icon="ui-icon ui-icon-tag"/>  
                                            <p:menuitem value="View All Products" url="http://localhost:8080/MerlionERP-war/SCM/products.xhtml" ajax="false" icon="ui-icon ui-icon-tag"/>  
                                            <p:menuitem value="New Material" url="http://localhost:8080/MerlionERP-war/SCM/addMaterial.xhtml" ajax="false" icon="ui-icon ui-icon-tag"/>                                      
                                            <p:menuitem value="View All Materials" url="http://localhost:8080/MerlionERP-war/SCM/materials.xhtml" ajax="false" icon="ui-icon ui-icon-tag" />
                                            <p:menuitem value="View Unhoused Inventories" url="http://localhost:8080/MerlionERP-war/SCM/unhousedInventories.xhtml" ajax="false" icon="ui-icon ui-icon-tag" />
                                            <p:menuitem value="View Inventory Movements" url="http://localhost:8080/MerlionERP-war/SCM/inventoryMovements.xhtml" ajax="false" icon="ui-icon ui-icon-tag" />

                                        </p:submenu>
                                        <p:submenu label="Warehouses" >
                                            <p:menuitem value="New Warehouse" url="http://localhost:8080/MerlionERP-war/SCM/addWarehouse.xhtml" ajax="false" icon="ui-icon ui-icon-tag"/>        
                                            <p:menuitem value= "View All Warehouses" url="http://localhost:8080/MerlionERP-war/SCM/warehouses.xhtml" ajax="false" icon="ui-icon ui-icon-tag" />
                                        </p:submenu>
                                        <p:submenu label="Shipments and Orders">
                                            <p:menuitem value="Delivery Orders" url="http://localhost:8080/MerlionERP-war/SCM/deliveryOrders.xhtml" ajax="false" icon="ui-icon ui-icon-tag"/>
                                            <p:menuitem value="Picking Orders" url="http://localhost:8080/MerlionERP-war/SCM/pickingOrders.xhtml" ajax="false" icon="ui-icon ui-icon-tag"/>            
                                        </p:submenu>
                                    </p:menu>
                                    <p:calendar mode="inline" style="font-size:11px;font-family:Tahoma"/>
                                </td>

                                <td style="vertical-align:top">

                                    <p:toolbar style="background-color:  #d9bb73;font-size: 90%;width:99.5%"> 
                                        <p:toolbarGroup align="left">  

                                            <p:commandButton value="Delete" title="Delete" image="ui-icon ui-icon-trash" oncomplete="warehouseDialog.show()"/>                                   

                                        </p:toolbarGroup>  
                                    </p:toolbar> 


                                    <p:dataTable id="inventoryTable" value="#{WarehouseManagedBean.unhousedInventoryList}"
                                                 var="inv" paginator="true" rows="5"
                                                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  

                                                 rowsPerPageTemplate="5,10,15" style="font-family:Tahoma;font-size:11px;width:100%"                      
                                                 emptyMessage="No data found with given criteria" widgetVar="inventoryTable"> 


                                        <f:facet name="header">                           
                                            <p:outputPanel style="text-align:right"  >
                                                <h:outputText value="Search all fields:"/>  
                                                <p:inputText id="globalFilter" onkeyup="inventoryTable.filter()" style="right:-100px;width:150px" />  
                                            </p:outputPanel>
                                        </f:facet>

                                        <p:column headerText="Batch ID" sortBy="#{inv.batchId}" filterBy="#{inv.batchId}"
                                                  style="width:100px" filterMatchMode="contains" >
                                            <h:outputText value="#{inv.batchId}"/>
                                        </p:column>


                                        <p:column headerText="Item ID"  sortBy="#{inv.itemId}" filterBy="#{inv.itemId}" 
                                                  style="width:150px" filterMatchMode="contains">   
                                            <h:outputText value="#{inv.itemId}" />
                                        </p:column>


                                        <p:column headerText="Item Name" sortBy="#{inv.name}" filterBy="#{inv.name}" 
                                                  style="width:250px" filterMatchMode="contains" >  

                                            <h:outputText value="#{inv.name}" />  

                                        </p:column>  

                                        <p:column headerText="Type" sortBy="#{inv.type}" filterBy="#{inv.type}" 
                                                  filterMatchMode="contains">
                                            <h:outputText value="#{inv.type}" />
                                        </p:column>

                                        <p:column headerText="In Hand Quantity" sortBy="#{inv.inHandQty}" filterBy="#{inv.inHandQty}" filterMatchMode="contains" 
                                                  style="width:100px" >  

                                            <h:outputText value="#{inv.inHandQty}" />  

                                        </p:column>  


                                        <p:column headerText="Reserved Quantity" sortBy="#{inv.reservedQty}" filterBy="#{inv.reservedQty}" 
                                                  filterMatchMode="contains" style="width:150px" >  

                                            <h:outputText value="#{inv.reservedQty}" />  
                                        </p:column>  


                                        <p:column style="width:100px">
                                            <p:commandButton value="Assign Inventory to Warehouse" ajax="true" update="assignInventoryPanel" oncomplete="assignInventoryDialog.show()" 
                                                             title="Assign Inventory to Warehouse">
                                                <f:setPropertyActionListener value="#{inv}" target="#{WarehouseManagedBean.selectedUnhousedInventory}"/>
                                            </p:commandButton>
                                        </p:column>

                                    </p:dataTable>

                                    <p:dialog header="Assign Inventory to Warehouse" widgetVar ="assignInventoryDialog" modal="true" width="800">
                                        <h:panelGrid id="assignInventoryPanel" columns="3">

                                            <h:outputText value="Choose Warehouse"/>
                                            <h:outputText value=":"/>
                                            <h:selectOneMenu id="chooseWarehouse" value="#{WarehouseManagedBean.warehouseId}">
                                                <f:selectItem itemLabel="Select Warehouse" itemValue=""/>
                                                <f:selectItems value="#{WarehouseManagedBean.warehouses}" var="warehouse"
                                                               itemLabel ="#{warehouse.id} - #{warehouse.name}" itemValue="#{warehouse.id}"/>

                                            </h:selectOneMenu>

                                            <p:commandButton value="Assign Inventory" ajax="true"  update="inventoryTable" 
                                                             oncomplete="assignInventoryDialog.hide()" actionListener="#{WarehouseManagedBean.assignInventory}" />
                                            <p:commandButton value="Cancel" oncomplete="assignInventoryDialog.hide()" /> 
                                        </h:panelGrid>
                                    </p:dialog>
                                </td></tr></table>
                    </div>

                    <div id="bottom" class="bottom">
                        <h:graphicImage value="/image/merlionfooter.jpg"/>
                    </div>
                </h:form>
            </h:body>
        </f:view>
    </f:view>
</html>
